<?php

namespace HelloAdmin\Controller;

class CrontabController extends CommonController {

    private $Crontab;

    public function __construct() {
        parent::__construct();
        $this->Crontab = new \HelloAdmin\Model\CrontabModel();
    }

    public function index(){

        $this->display('Index/crontab');
    }

    public function listData(){
        $search = I('post.search');
        if(!empty($search)){
            $where = "`url` like '{$search}%'";
        }
        $data = $this->Crontab->getList($where,'',$this->offset,$this->limit);
        echo (json_encode($data));
    }

    public function addCrontab(){
        if(empty($_POST['url'])){
            $this->display('Index/addCrontab');exit;
        }
        $data['url'] = I('post.url');
        $data['remark'] = I('post.remark');
        $data['type'] = I('post.type');
        $data['ctime'] = time();
        if($this->Crontab->add($data)){
            $this->layerIfreamRe('添加成功');
        }
        $this->error('添加失败');
    }

    public function updateField(){
        if($this->Crontab->updateField()){
            echo 'success';exit;
        }
    }
}
